use strict;
use warnings;

package Contact::Address;

use base qw(My::DB::Object);

__PACKAGE__->meta->setup(
	table   => 'Address',
	columns => [
		'id'         => { 'type' => 'serial',    'primary_key' => 1,   'not_null' => 1 },
		'person_id'  => { 'type' => 'int',       'not_null'    => 1 },
		'address_1'  => { 'type' => 'varchar',   'length'      => 255, 'not_null' => 1 },
		'address_2'  => { 'type' => 'varchar',   'length'      => 255 },
		'city'       => { 'type' => 'varchar',   'length'      => 32,  'not_null' => 1 },
		'state'      => { 'type' => 'varchar',   'length'      => 32,  'not_null' => 1 },
		'postcode'   => { 'type' => 'varchar',   'length'      => 8,   'not_null' => 1 },
		'country_id' => { 'type' => 'varchar',   'length'      => 2,   'not_null' => 1 },
		'active'     => { 'type' => 'boolean',       'not_null'    => 1,   'default'  => 1 },
		'created'    => { 'type' => 'timestamp', 'not_null'    => 1,   'default'  => 'now' },
		'retired'    => { 'type' => 'timestamp', 'not_null'    => 0 },
	],
	relationships => [
		owner   => { type => 'one to one',  class => 'Person',  column_map => { 'person_id'  => 'id' }, },
		country => { type => 'many to one', class => 'Country', column_map => { 'country_id' => 'id' }, },
		phones => { type => 'many to many', map_class => 'Contact::AddressPhoneMap', map_from => 'address', map_to => 'phone' },
	],
);

1;
